/**
 * @copyright   Shanghai Kuntai Software Technology Co., Ltd. 2025
 * @license     MIT
 * @file        KTCCoreDefine.h
 * @date		2021-9-16
 * @brief       Core defines
 */
#ifndef KTCCoreDefine_H_
#define KTCCoreDefine_H_

/** @brief CAA min pixel value, 0.000001m = 0.001mm */
#define KTC_MIN_LENGTH_VALUE_M 1e-6

/** @brief CAA min pixel value, 0.001mm */
#define KTC_MIN_LENGTH_VALUE_MM 0.001

/** TODO: MAX LENGTH in CAA?
 * FLT_MAX          3.402823466e+38F
 */
#define KTC_FLT_MAX_LENGTH 1e38F

#pragma region functions

/**
 * @brief CAA pointer Release
 * @param[in] pCAA CAA feature pointer
 */
#define KTCRelease(pCAA) \
    if (NULL != pCAA) {  \
        pCAA->Release(); \
        pCAA = NULL;     \
    }

/**
 * @brief empty the CAA ISO or HSO
 * @param[in] OBJECT ISO or HSO pointer
 */
#define KTCEmpty(OBJECT)  \
    if (NULL != OBJECT) { \
        OBJECT->Empty();  \
        OBJECT = NULL;    \
    }

/**
 * @brief CAA pointer RequestDelayedDestruction
 * @param[in] pCAA CAA feature pointer
 */
#define KTCRequestDelayedDestruction(pCAA) \
    if (NULL != pCAA) {                    \
        pCAA->RequestDelayedDestruction(); \
        pCAA = NULL;                       \
    }

/** @brief No Doc. */
#define KTCRequestDelayedDestructionIf KTCRequestDelayedDestruction

/** @brief No Selection String. */
#define KTC_NO_SELECTION "(No Selection)"

/**
 * @brief Kevin system set version for CAA feature.
 * @param[in] id target version id
 * @return if failed, return hr. if ok, do not break.
 */
#define KTC_FEATURE_SETVERSION(id) \
    {                              \
        hr = this->SetVersion(id); \
        if (FAILED(hr)) return hr; \
    }

/** @brief give the icon of direction sign. */
#define KTC_DIRECTION_SIGN_ICON(sign) (sign) < 0 ? "I_KTCDirectionDown" : "I_KTCDirectionUp"

/** @brief invert the direction sign. */
#define KTC_DIRECTION_SIGN_INVERT(sign) sign = (sign) < 0 ? 1 : -1

/** @brief direction down,  sign < 0. */
#define KTC_DIRECTION_SIGN_DOWN(sign) (sign) < 0

#pragma endregion functions

// enum
namespace KTC {
/** @brief Feature Mode */
enum FeatureMode {
    FeatureModeEdit     = 0,
    FeatureModeCreation = 1,
};

/** @brief value action mode */
enum ValueActionMode {
    ValueNormal   = 0, // if exist , remove, otherwise append
    ValueAdd      = 1, // append only
    ValueSubtract = 2, // remove only
};

typedef int Key_Item;

#ifndef CATULONG64
typedef unsigned long long CtxMenuDef;
#else
typedef CATULONG64 CtxMenuDef;
#endif

} // namespace KTC

// JSON Define
#define KT_STRING_JSON_APPEND_VALUE(NAME) "\"" #NAME "\":" << NAME
#define KT_STRING_JSON_APPEND_FLOAT(NAME) "\"" #NAME "\":" << (float)NAME
#define KT_STRING_JSON_APPEND_STRING(NAME) "\"" #NAME "\":\"" << NAME << "\""

#endif // KTCCoreDefine_H_
